import os
import sys
CURRENT_DIR = os.getcwd()
SRC_DIR = os.path.join(CURRENT_DIR, 'src')
sys.path.append(SRC_DIR)
from util import device


print '### Setup script for FluidVoice V4'
un = raw_input('Username:')
id = raw_input('ID (int, should be unique):')
id = int(id)

print '### Creating profile file'
f = open('src/profile', mode='wa')
f.write(un + ',' + str(id))
f.close()

print '### Creating bookmark'''
bookmarks_template_path = os.path.join(CURRENT_DIR, 'deploy/MyBookmarks.template')
bookmarks_file_path = os.path.join(CURRENT_DIR, 'deploy/MyBookmarks.xml')
FLASH_UI_PATH = os.path.join(CURRENT_DIR, 'flash/src/FluidFlashApp.swf')

f = open(bookmarks_template_path, mode='ra')
template = f.read()
spliced = template.replace('%%%FV_UI_PATH%%%', FLASH_UI_PATH)
f.close()
f = open(bookmarks_file_path, mode='wa')
f.write(spliced)
f.close()

bookmarks_link_dst = '/home/user/.bookmarks/MyBookmarks.xml'
if os.path.exists(bookmarks_link_dst):
    os.remove(bookmarks_link_dst)
os.link(bookmarks_file_path, bookmarks_link_dst)

print '### Creating FlashTrust settings'
FLASH_TRUST_PATH = '/home/user/.macromedia/Flash_Player/#Security/FlashPlayerTrust'
if not os.path.exists(FLASH_TRUST_PATH):
    os.makedirs(FLASH_TRUST_PATH)
trust_link_dst = os.path.join(FLASH_TRUST_PATH, 'trust.cfg')
if os.path.exists(trust_link_dst):
    os.remove(trust_link_dst)

trust_link_src = os.path.join(CURRENT_DIR, 'deploy/trust.cfg')

f = open(trust_link_src, mode='w')
print 'Writing',FLASH_UI_PATH
f.write(FLASH_UI_PATH + '\n')
f.close()

print 'Linking to ',trust_link_src,'from',trust_link_dst
os.link(trust_link_src, trust_link_dst)

print '### Setup complete.'''